#ifndef PLAYER_H
#define PLAYER_H

#include <jni.h>
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>

class AudioPlayer {
public:
    AudioPlayer();
    ~AudioPlayer();

    // play接口，用于播放音频buffer数据
    void play(void *buffer, int bufferSize, int numChannels, int sampleRate);

private:
    // OpenSL ES相关对象指针
    SLObjectItf engineObject;
    SLEngineItf engineEngine;
    SLObjectItf outputMixObject;
    SLObjectItf bufferQueueObject;
    SLPlayItf playInterface;
    SLAndroidSimpleBufferQueueItf bufferQueueInterface;

    // 音频参数相关变量
    int m_numChannels;
    int m_sampleRate;

    // 用于管理音频数据缓冲区
    void *m_audioBuffer;
    int m_bufferSize;

    // 初始化OpenSL ES相关环境的私有函数
    bool initOpenSLES();
    // 音频数据回调函数，由OpenSL ES调用
    static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bufferQueue, void *context);
};

#endif // PLAYER_H
